var _excluded = ['leftColumns', 'rightColumns', 'tableProps'];
function _extends() {
  _extends = Object.assign
    ? Object.assign.bind()
    : function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];
          for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }
        return target;
      };
  return _extends.apply(this, arguments);
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
import { difference } from '@szzj/utils';
import { Transfer as AntdTransfer, Table } from 'antd';
import 'antd/es/transfer/style/index.js';
import React from 'react';
import createField from '../../createField';
var TableTransfer = function TableTransfer(_ref) {
  var leftColumns = _ref.leftColumns,
    rightColumns = _ref.rightColumns,
    _ref$tableProps = _ref.tableProps,
    tableProps = _ref$tableProps === void 0 ? {} : _ref$tableProps,
    rest = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/ React.createElement(AntdTransfer, rest, function (_ref2) {
    var direction = _ref2.direction,
      filteredItems = _ref2.filteredItems,
      onItemSelectAll = _ref2.onItemSelectAll,
      onItemSelect = _ref2.onItemSelect,
      listSelectedKeys = _ref2.selectedKeys,
      listDisabled = _ref2.disabled;
    var columns = direction === 'left' ? leftColumns : rightColumns;
    var rowSelection = {
      getCheckboxProps: function getCheckboxProps(item) {
        return {
          disabled: listDisabled || item.disabled,
        };
      },
      onSelectAll: function onSelectAll(selected, selectedRows) {
        var treeSelectedKeys = selectedRows
          .filter(function (item) {
            return !item.disabled;
          })
          .map(function (_ref3) {
            var key = _ref3.key;
            return key;
          });
        var diffKeys = selected
          ? difference(treeSelectedKeys, listSelectedKeys)
          : difference(listSelectedKeys, treeSelectedKeys);
        onItemSelectAll(diffKeys, selected);
      },
      onSelect: function onSelect(_ref4, selected) {
        var key = _ref4.key;
        onItemSelect(key, selected);
      },
      selectedRowKeys: listSelectedKeys,
    };
    return /*#__PURE__*/ React.createElement(
      Table,
      _extends(
        {
          rowSelection: rowSelection,
          dataSource: filteredItems,
          size: 'small',
          // @ts-ignore
          style: {
            pointerEvents: listDisabled ? 'none' : null,
          },
        },
        tableProps,
        {
          // @ts-ignore
          columns: columns,
          // @ts-ignore
          onRow: function onRow(_ref5) {
            var key = _ref5.key,
              itemDisabled = _ref5.disabled;
            return {
              onClick: function onClick() {
                if (itemDisabled || listDisabled) return;
                onItemSelect(key, !listSelectedKeys.includes(key));
              },
            };
          },
        },
      ),
    );
  });
};
export default createField(TableTransfer, {
  defaultFormItemProps: {
    valuePropName: 'targetKeys',
  },
});
